{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "39c294a5",
   "metadata": {
    "papermill": {
     "duration": 0.044353,
     "end_time": "2022-03-20T02:19:14.265063",
     "exception": false,
     "start_time": "2022-03-20T02:19:14.220710",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 0.Overview\n",
    "**Tutorial**: sequential-model-fixed-missing-last-item\n",
    "\n",
    "**Author**: [astrung](https://github.com/astrung)\n",
    "\n",
    "**Original link**: [notebook](https://www.kaggle.com/code/astrung/sequential-model-fixed-missing-last-item)\n",
    "\n",
    "**Edit**:\n",
    "* In my previous notebooks([here](https://www.kaggle.com/code/astrung/lstm-sequential-modelwith-item-features-tutorial) and [here](https://www.kaggle.com/code/astrung/lstm-sequential-modelwith-item-features-tutorial)), we have used test_data with `full_sort_topk`,but due to the limit of full_sort_topk we have missed last item for submited recommendation. Someone asked me about how can use all items as input features for recommendation in this [comment](https://www.kaggle.com/code/astrung/recbole-lstm-sequential-for-recomendation-tutorial/comments#1723707). \n",
    "* So i created a notebook [here](https://www.kaggle.com/code/astrung/recbole-using-all-items-for-prediction) for address there questions in detail, and this notebook is an improved of my [previous notebook](https://www.kaggle.com/code/astrung/lstm-sequential-modelwith-item-features-tutorial), applying our new function (using all item as input features without `full_sort_topk`) for this competition.\n",
    "* I also create a improved version for adding item features into model in this [notebook](https://www.kaggle.com/astrung/lstm-model-with-item-infor-fix-missing-last-item). It improved a little score when add item features for recommendation\n",
    "\n",
    "- - -\n",
    "\n",
    "\n",
    "This notebook demonstrate how to use LSTM for recomendation system.\n",
    "I am using Recbole as an open source, as it has so many built-in models for recommendation(CNN, GRU-LSTM, Context-aware, Graph). In this notebook, we tried to use GRU/LSTM model for testing effect of sequential model for recommendation.\n",
    "\n",
    "Due to memory limit and faster testing purpose, we will just use data in 2020.\n",
    "\n",
    "If you want to use with all of interactions in all time, i have created a new atomic dataset here for you: https://www.kaggle.com/astrung/hm-atomic-interation\n",
    "\n",
    "We also have other limit: we only train model and predict with users who buy more than 40 items and items which is bought by more than 40 people.\n",
    "\n",
    "We will follow below steps for creating model:\n",
    "\n",
    "1. In order to use Recbole, we create atomic file from interaction data\n",
    "2. Because we only use Recbole model for predicting with users who buy more than 40 items, other users will need to fill by default recomendation items. We create most viewed items in last month as defautl recomendation\n",
    "3. We create dataset and train model in recbole.\n",
    "4. We create prediction result by trained model\n",
    "5. We combine recomendation result from most viewed items in last month and Recbole predicted model.\n",
    "\n",
    "I will explain more detail in following cells.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "88df5f58",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:19:14.361854Z",
     "iopub.status.busy": "2022-03-20T02:19:14.360768Z",
     "iopub.status.idle": "2022-03-20T02:19:35.871726Z",
     "shell.execute_reply": "2022-03-20T02:19:35.870606Z",
     "shell.execute_reply.started": "2022-03-19T09:03:25.544116Z"
    },
    "papermill": {
     "duration": 21.563461,
     "end_time": "2022-03-20T02:19:35.872051",
     "exception": false,
     "start_time": "2022-03-20T02:19:14.308590",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting recbole\r\n",
      "  Downloading recbole-1.0.1-py3-none-any.whl (2.0 MB)\r\n",
      "     |████████████████████████████████| 2.0 MB 618 kB/s            \r\n",
      "\u001b[?25hRequirement already satisfied: colorama==0.4.4 in /opt/conda/lib/python3.7/site-packages (from recbole) (0.4.4)\r\n",
      "Requirement already satisfied: scikit-learn>=0.23.2 in /opt/conda/lib/python3.7/site-packages (from recbole) (0.23.2)\r\n",
      "Requirement already satisfied: pyyaml>=5.1.0 in /opt/conda/lib/python3.7/site-packages (from recbole) (6.0)\r\n",
      "Collecting colorlog==4.7.2\r\n",
      "  Downloading colorlog-4.7.2-py2.py3-none-any.whl (10 kB)\r\n",
      "Requirement already satisfied: torch>=1.7.0 in /opt/conda/lib/python3.7/site-packages (from recbole) (1.9.1)\r\n",
      "Collecting scipy==1.6.0\r\n",
      "  Downloading scipy-1.6.0-cp37-cp37m-manylinux1_x86_64.whl (27.4 MB)\r\n",
      "     |████████████████████████████████| 27.4 MB 125 kB/s             \r\n",
      "\u001b[?25hRequirement already satisfied: pandas>=1.0.5 in /opt/conda/lib/python3.7/site-packages (from recbole) (1.3.5)\r\n",
      "Requirement already satisfied: tqdm>=4.48.2 in /opt/conda/lib/python3.7/site-packages (from recbole) (4.62.3)\r\n",
      "Requirement already satisfied: numpy>=1.17.2 in /opt/conda/lib/python3.7/site-packages (from recbole) (1.20.3)\r\n",
      "Requirement already satisfied: tensorboard>=2.5.0 in /opt/conda/lib/python3.7/site-packages (from recbole) (2.6.0)\r\n",
      "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.7/site-packages (from pandas>=1.0.5->recbole) (2.8.2)\r\n",
      "Requirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.7/site-packages (from pandas>=1.0.5->recbole) (2021.3)\r\n",
      "Requirement already satisfied: joblib>=0.11 in /opt/conda/lib/python3.7/site-packages (from scikit-learn>=0.23.2->recbole) (1.1.0)\r\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.7/site-packages (from scikit-learn>=0.23.2->recbole) (3.0.0)\r\n",
      "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (0.6.1)\r\n",
      "Requirement already satisfied: wheel>=0.26 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (0.37.0)\r\n",
      "Requirement already satisfied: setuptools>=41.0.0 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (59.5.0)\r\n",
      "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (1.8.0)\r\n",
      "Requirement already satisfied: absl-py>=0.4 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (0.15.0)\r\n",
      "Requirement already satisfied: protobuf>=3.6.0 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (3.19.1)\r\n",
      "Requirement already satisfied: google-auth<2,>=1.6.3 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (1.35.0)\r\n",
      "Requirement already satisfied: requests<3,>=2.21.0 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (2.26.0)\r\n",
      "Requirement already satisfied: grpcio>=1.24.3 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (1.43.0)\r\n",
      "Requirement already satisfied: werkzeug>=0.11.15 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (2.0.2)\r\n",
      "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (0.4.6)\r\n",
      "Requirement already satisfied: markdown>=2.6.8 in /opt/conda/lib/python3.7/site-packages (from tensorboard>=2.5.0->recbole) (3.3.6)\r\n",
      "Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.7/site-packages (from torch>=1.7.0->recbole) (4.0.1)\r\n",
      "Requirement already satisfied: six in /opt/conda/lib/python3.7/site-packages (from absl-py>=0.4->tensorboard>=2.5.0->recbole) (1.16.0)\r\n",
      "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /opt/conda/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard>=2.5.0->recbole) (4.2.4)\r\n",
      "Requirement already satisfied: rsa<5,>=3.1.4 in /opt/conda/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard>=2.5.0->recbole) (4.8)\r\n",
      "Requirement already satisfied: pyasn1-modules>=0.2.1 in /opt/conda/lib/python3.7/site-packages (from google-auth<2,>=1.6.3->tensorboard>=2.5.0->recbole) (0.2.7)\r\n",
      "Requirement already satisfied: requests-oauthlib>=0.7.0 in /opt/conda/lib/python3.7/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard>=2.5.0->recbole) (1.3.0)\r\n",
      "Requirement already satisfied: importlib-metadata>=4.4 in /opt/conda/lib/python3.7/site-packages (from markdown>=2.6.8->tensorboard>=2.5.0->recbole) (4.10.1)\r\n",
      "Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard>=2.5.0->recbole) (3.1)\r\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard>=2.5.0->recbole) (2021.10.8)\r\n",
      "Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/conda/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard>=2.5.0->recbole) (2.0.9)\r\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard>=2.5.0->recbole) (1.26.7)\r\n",
      "Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard>=2.5.0->recbole) (3.6.0)\r\n",
      "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /opt/conda/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard>=2.5.0->recbole) (0.4.8)\r\n",
      "Requirement already satisfied: oauthlib>=3.0.0 in /opt/conda/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard>=2.5.0->recbole) (3.1.1)\r\n",
      "Installing collected packages: scipy, colorlog, recbole\r\n",
      "  Attempting uninstall: scipy\r\n",
      "    Found existing installation: scipy 1.7.3\r\n",
      "    Uninstalling scipy-1.7.3:\r\n",
      "      Successfully uninstalled scipy-1.7.3\r\n",
      "  Attempting uninstall: colorlog\r\n",
      "    Found existing installation: colorlog 6.6.0\r\n",
      "    Uninstalling colorlog-6.6.0:\r\n",
      "      Successfully uninstalled colorlog-6.6.0\r\n",
      "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\r\n",
      "yellowbrick 1.3.post1 requires numpy<1.20,>=1.16.0, but you have numpy 1.20.3 which is incompatible.\r\n",
      "pdpbox 0.2.1 requires matplotlib==3.1.1, but you have matplotlib 3.5.1 which is incompatible.\r\n",
      "imbalanced-learn 0.9.0 requires scikit-learn>=1.0.1, but you have scikit-learn 0.23.2 which is incompatible.\r\n",
      "featuretools 1.4.1 requires numpy>=1.21.0, but you have numpy 1.20.3 which is incompatible.\r\n",
      "arviz 0.11.4 requires typing-extensions<4,>=3.7.4.3, but you have typing-extensions 4.0.1 which is incompatible.\u001b[0m\r\n",
      "Successfully installed colorlog-4.7.2 recbole-1.0.1 scipy-1.6.0\r\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\r\n"
     ]
    }
   ],
   "source": [
    "!pip install recbole"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4afb60af",
   "metadata": {
    "papermill": {
     "duration": 0.067053,
     "end_time": "2022-03-20T02:19:36.014583",
     "exception": false,
     "start_time": "2022-03-20T02:19:35.947530",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 1. Create atomic file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a1d01d80",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:19:36.155095Z",
     "iopub.status.busy": "2022-03-20T02:19:36.154434Z",
     "iopub.status.idle": "2022-03-20T02:20:43.709687Z",
     "shell.execute_reply": "2022-03-20T02:20:43.710329Z",
     "shell.execute_reply.started": "2022-03-19T09:03:46.361987Z"
    },
    "papermill": {
     "duration": 67.62903,
     "end_time": "2022-03-20T02:20:43.710549",
     "exception": false,
     "start_time": "2022-03-20T02:19:36.081519",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t_dat</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>article_id</th>\n",
       "      <th>price</th>\n",
       "      <th>sales_channel_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0663713001</td>\n",
       "      <td>0.050831</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0541518023</td>\n",
       "      <td>0.030492</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0505221004</td>\n",
       "      <td>0.015237</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687003</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687004</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        t_dat                                        customer_id  article_id  \\\n",
       "0  2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...  0663713001   \n",
       "1  2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...  0541518023   \n",
       "2  2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0505221004   \n",
       "3  2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0685687003   \n",
       "4  2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0685687004   \n",
       "\n",
       "      price  sales_channel_id  \n",
       "0  0.050831                 2  \n",
       "1  0.030492                 2  \n",
       "2  0.015237                 2  \n",
       "3  0.016932                 2  \n",
       "4  0.016932                 2  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import gc\n",
    "df = pd.read_csv(r\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\", \n",
    "                 dtype={'article_id': 'str'})\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "535f1f8f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:20:45.628510Z",
     "iopub.status.busy": "2022-03-20T02:20:45.627430Z",
     "iopub.status.idle": "2022-03-20T02:20:50.180018Z",
     "shell.execute_reply": "2022-03-20T02:20:50.179424Z",
     "shell.execute_reply.started": "2022-03-19T09:04:50.295558Z"
    },
    "papermill": {
     "duration": 6.4014,
     "end_time": "2022-03-20T02:20:50.180176",
     "exception": false,
     "start_time": "2022-03-20T02:20:43.778776",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t_dat</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>article_id</th>\n",
       "      <th>price</th>\n",
       "      <th>sales_channel_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0663713001</td>\n",
       "      <td>0.050831</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0541518023</td>\n",
       "      <td>0.030492</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0505221004</td>\n",
       "      <td>0.015237</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687003</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687004</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788319</th>\n",
       "      <td>2020-09-22</td>\n",
       "      <td>fff2282977442e327b45d8c89afde25617d00124d0f999...</td>\n",
       "      <td>0929511001</td>\n",
       "      <td>0.059305</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788320</th>\n",
       "      <td>2020-09-22</td>\n",
       "      <td>fff2282977442e327b45d8c89afde25617d00124d0f999...</td>\n",
       "      <td>0891322004</td>\n",
       "      <td>0.042356</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788321</th>\n",
       "      <td>2020-09-22</td>\n",
       "      <td>fff380805474b287b05cb2a7507b9a013482f7dd0bce0e...</td>\n",
       "      <td>0918325001</td>\n",
       "      <td>0.043203</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788322</th>\n",
       "      <td>2020-09-22</td>\n",
       "      <td>fff4d3a8b1f3b60af93e78c30a7cb4cf75edaf2590d3e5...</td>\n",
       "      <td>0833459002</td>\n",
       "      <td>0.006763</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788323</th>\n",
       "      <td>2020-09-22</td>\n",
       "      <td>fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...</td>\n",
       "      <td>0898573003</td>\n",
       "      <td>0.033881</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>31788324 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              t_dat                                        customer_id  \\\n",
       "0        2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "1        2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "2        2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...   \n",
       "3        2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...   \n",
       "4        2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...   \n",
       "...             ...                                                ...   \n",
       "31788319 2020-09-22  fff2282977442e327b45d8c89afde25617d00124d0f999...   \n",
       "31788320 2020-09-22  fff2282977442e327b45d8c89afde25617d00124d0f999...   \n",
       "31788321 2020-09-22  fff380805474b287b05cb2a7507b9a013482f7dd0bce0e...   \n",
       "31788322 2020-09-22  fff4d3a8b1f3b60af93e78c30a7cb4cf75edaf2590d3e5...   \n",
       "31788323 2020-09-22  fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...   \n",
       "\n",
       "          article_id     price  sales_channel_id  \n",
       "0         0663713001  0.050831                 2  \n",
       "1         0541518023  0.030492                 2  \n",
       "2         0505221004  0.015237                 2  \n",
       "3         0685687003  0.016932                 2  \n",
       "4         0685687004  0.016932                 2  \n",
       "...              ...       ...               ...  \n",
       "31788319  0929511001  0.059305                 2  \n",
       "31788320  0891322004  0.042356                 2  \n",
       "31788321  0918325001  0.043203                 1  \n",
       "31788322  0833459002  0.006763                 1  \n",
       "31788323  0898573003  0.033881                 2  \n",
       "\n",
       "[31788324 rows x 5 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['t_dat'] = pd.to_datetime(df['t_dat'], format=\"%Y-%m-%d\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "28043b68",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:20:50.327100Z",
     "iopub.status.busy": "2022-03-20T02:20:50.325671Z",
     "iopub.status.idle": "2022-03-20T02:20:50.923223Z",
     "shell.execute_reply": "2022-03-20T02:20:50.923781Z",
     "shell.execute_reply.started": "2022-03-19T09:04:56.537845Z"
    },
    "papermill": {
     "duration": 0.673267,
     "end_time": "2022-03-20T02:20:50.923977",
     "exception": false,
     "start_time": "2022-03-20T02:20:50.250710",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>t_dat</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>article_id</th>\n",
       "      <th>price</th>\n",
       "      <th>sales_channel_id</th>\n",
       "      <th>timestamp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0663713001</td>\n",
       "      <td>0.050831</td>\n",
       "      <td>2</td>\n",
       "      <td>1537401600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0541518023</td>\n",
       "      <td>0.030492</td>\n",
       "      <td>2</td>\n",
       "      <td>1537401600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0505221004</td>\n",
       "      <td>0.015237</td>\n",
       "      <td>2</td>\n",
       "      <td>1537401600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687003</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "      <td>1537401600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>00007d2de826758b65a93dd24ce629ed66842531df6699...</td>\n",
       "      <td>0685687004</td>\n",
       "      <td>0.016932</td>\n",
       "      <td>2</td>\n",
       "      <td>1537401600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       t_dat                                        customer_id  article_id  \\\n",
       "0 2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...  0663713001   \n",
       "1 2018-09-20  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...  0541518023   \n",
       "2 2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0505221004   \n",
       "3 2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0685687003   \n",
       "4 2018-09-20  00007d2de826758b65a93dd24ce629ed66842531df6699...  0685687004   \n",
       "\n",
       "      price  sales_channel_id   timestamp  \n",
       "0  0.050831                 2  1537401600  \n",
       "1  0.030492                 2  1537401600  \n",
       "2  0.015237                 2  1537401600  \n",
       "3  0.016932                 2  1537401600  \n",
       "4  0.016932                 2  1537401600  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "df['timestamp'] = df.t_dat.values.astype(np.int64) // 10 ** 9\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b77607f",
   "metadata": {
    "papermill": {
     "duration": 0.06931,
     "end_time": "2022-03-20T02:20:51.061588",
     "exception": false,
     "start_time": "2022-03-20T02:20:50.992278",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**We fill with data in only 2020(timestapm > > 1585620000) and create inter file**\n",
    "For anyone need instruction about inter file, please check below links:\n",
    "* https://recbole.io/docs/user_guide/data_intro.html\n",
    "* https://recbole.io/docs/user_guide/data/atomic_files.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "892d6c5d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:20:51.240531Z",
     "iopub.status.busy": "2022-03-20T02:20:51.237724Z",
     "iopub.status.idle": "2022-03-20T02:20:53.162136Z",
     "shell.execute_reply": "2022-03-20T02:20:53.161463Z",
     "shell.execute_reply.started": "2022-03-19T09:04:57.127124Z"
    },
    "papermill": {
     "duration": 2.032094,
     "end_time": "2022-03-20T02:20:53.162319",
     "exception": false,
     "start_time": "2022-03-20T02:20:51.130225",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id:token</th>\n",
       "      <th>item_id:token</th>\n",
       "      <th>timestamp:float</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23934157</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0727808001</td>\n",
       "      <td>1585699200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23934158</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0727808007</td>\n",
       "      <td>1585699200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23934159</th>\n",
       "      <td>000563485cbb7850b0a93c6606f89c5b961c6647d1bd48...</td>\n",
       "      <td>0567532015</td>\n",
       "      <td>1585699200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23934160</th>\n",
       "      <td>000563485cbb7850b0a93c6606f89c5b961c6647d1bd48...</td>\n",
       "      <td>0706104009</td>\n",
       "      <td>1585699200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23934161</th>\n",
       "      <td>00083cda041544b2fbb0e0d2905ad17da7cf1007526fb4...</td>\n",
       "      <td>0783504004</td>\n",
       "      <td>1585699200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788319</th>\n",
       "      <td>fff2282977442e327b45d8c89afde25617d00124d0f999...</td>\n",
       "      <td>0929511001</td>\n",
       "      <td>1600732800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788320</th>\n",
       "      <td>fff2282977442e327b45d8c89afde25617d00124d0f999...</td>\n",
       "      <td>0891322004</td>\n",
       "      <td>1600732800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788321</th>\n",
       "      <td>fff380805474b287b05cb2a7507b9a013482f7dd0bce0e...</td>\n",
       "      <td>0918325001</td>\n",
       "      <td>1600732800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788322</th>\n",
       "      <td>fff4d3a8b1f3b60af93e78c30a7cb4cf75edaf2590d3e5...</td>\n",
       "      <td>0833459002</td>\n",
       "      <td>1600732800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31788323</th>\n",
       "      <td>fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...</td>\n",
       "      <td>0898573003</td>\n",
       "      <td>1600732800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7854167 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              user_id:token item_id:token  \\\n",
       "23934157  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...    0727808001   \n",
       "23934158  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...    0727808007   \n",
       "23934159  000563485cbb7850b0a93c6606f89c5b961c6647d1bd48...    0567532015   \n",
       "23934160  000563485cbb7850b0a93c6606f89c5b961c6647d1bd48...    0706104009   \n",
       "23934161  00083cda041544b2fbb0e0d2905ad17da7cf1007526fb4...    0783504004   \n",
       "...                                                     ...           ...   \n",
       "31788319  fff2282977442e327b45d8c89afde25617d00124d0f999...    0929511001   \n",
       "31788320  fff2282977442e327b45d8c89afde25617d00124d0f999...    0891322004   \n",
       "31788321  fff380805474b287b05cb2a7507b9a013482f7dd0bce0e...    0918325001   \n",
       "31788322  fff4d3a8b1f3b60af93e78c30a7cb4cf75edaf2590d3e5...    0833459002   \n",
       "31788323  fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...    0898573003   \n",
       "\n",
       "          timestamp:float  \n",
       "23934157       1585699200  \n",
       "23934158       1585699200  \n",
       "23934159       1585699200  \n",
       "23934160       1585699200  \n",
       "23934161       1585699200  \n",
       "...                   ...  \n",
       "31788319       1600732800  \n",
       "31788320       1600732800  \n",
       "31788321       1600732800  \n",
       "31788322       1600732800  \n",
       "31788323       1600732800  \n",
       "\n",
       "[7854167 rows x 3 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = df[df['timestamp'] > 1585620000][['customer_id', 'article_id', 'timestamp']].rename(\n",
    "    columns={'customer_id': 'user_id:token', 'article_id': 'item_id:token', 'timestamp': 'timestamp:float'})\n",
    "temp"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae5d0ec3",
   "metadata": {
    "papermill": {
     "duration": 0.071609,
     "end_time": "2022-03-20T02:20:53.304714",
     "exception": false,
     "start_time": "2022-03-20T02:20:53.233105",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "We save atomic file in dataset format for using with recbole"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "37f98c58",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:20:53.493765Z",
     "iopub.status.busy": "2022-03-20T02:20:53.454009Z",
     "iopub.status.idle": "2022-03-20T02:21:31.746398Z",
     "shell.execute_reply": "2022-03-20T02:21:31.746994Z",
     "shell.execute_reply.started": "2022-03-19T09:04:58.814912Z"
    },
    "papermill": {
     "duration": 38.371105,
     "end_time": "2022-03-20T02:21:31.747188",
     "exception": false,
     "start_time": "2022-03-20T02:20:53.376083",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "160"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "!mkdir /kaggle/working/recbox_data\n",
    "temp.to_csv('/kaggle/working/recbox_data/recbox_data.inter', index=False, sep='\\t')\n",
    "del temp\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c0c4ed1",
   "metadata": {
    "papermill": {
     "duration": 0.069772,
     "end_time": "2022-03-20T02:21:31.887123",
     "exception": false,
     "start_time": "2022-03-20T02:21:31.817351",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 2. We create defautl recomendation for user who can not be predicted by sequential model.\n",
    "I use this approach in notebook: https://www.kaggle.com/hervind/h-m-faster-trending-products-weekly You can check it for more detail information. I will juse copy only code here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f06dc674",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:21:32.036991Z",
     "iopub.status.busy": "2022-03-20T02:21:32.035445Z",
     "iopub.status.idle": "2022-03-20T02:21:32.037770Z",
     "shell.execute_reply": "2022-03-20T02:21:32.038388Z",
     "shell.execute_reply.started": "2022-03-19T09:05:34.218845Z"
    },
    "papermill": {
     "duration": 0.079481,
     "end_time": "2022-03-20T02:21:32.038570",
     "exception": false,
     "start_time": "2022-03-20T02:21:31.959089",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c6fb55ab",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:21:32.186012Z",
     "iopub.status.busy": "2022-03-20T02:21:32.185168Z",
     "iopub.status.idle": "2022-03-20T02:22:25.689493Z",
     "shell.execute_reply": "2022-03-20T02:22:25.690149Z",
     "shell.execute_reply.started": "2022-03-19T09:05:34.226052Z"
    },
    "papermill": {
     "duration": 53.581364,
     "end_time": "2022-03-20T02:22:25.690334",
     "exception": false,
     "start_time": "2022-03-20T02:21:32.108970",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((1371980, 2), (1371980, 2), (1371980, 2))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub0 = pd.read_csv('../input/hm-pre-recommendation/submissio_byfone_chris.csv').sort_values('customer_id').reset_index(drop=True)\n",
    "sub1 = pd.read_csv('../input/hm-pre-recommendation/submission_trending.csv').sort_values('customer_id').reset_index(drop=True)\n",
    "sub2 = pd.read_csv('../input/hm-pre-recommendation/submission_exponential_decay.csv').sort_values('customer_id').reset_index(drop=True)\n",
    "\n",
    "sub0.shape, sub1.shape, sub2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "502968dc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:22:25.839198Z",
     "iopub.status.busy": "2022-03-20T02:22:25.837927Z",
     "iopub.status.idle": "2022-03-20T02:22:26.105094Z",
     "shell.execute_reply": "2022-03-20T02:22:26.105816Z",
     "shell.execute_reply.started": "2022-03-19T09:06:27.429248Z"
    },
    "papermill": {
     "duration": 0.344956,
     "end_time": "2022-03-20T02:22:26.106058",
     "exception": false,
     "start_time": "2022-03-20T02:22:25.761102",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction0</th>\n",
       "      <th>prediction1</th>\n",
       "      <th>prediction2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 07...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 07...</td>\n",
       "      <td>0568601043 0924243001 0924243002 0918522001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0739590027 0723529001 08...</td>\n",
       "      <td>0826211002 0800436010 0739590027 0723529001 08...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 07...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 07...</td>\n",
       "      <td>0794321007 0924243001 0924243002 0918522001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0751471001 0706016001 06...</td>\n",
       "      <td>0448509014 0573085028 0751471001 0706016001 06...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0896152002 0818320001 09...</td>\n",
       "      <td>0730683050 0791587015 0896152002 0818320001 09...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                         prediction0  \\\n",
       "0  0568601043 0568601006 0656719005 0745232001 07...   \n",
       "1  0826211002 0800436010 0739590027 0723529001 08...   \n",
       "2  0794321007 0852643001 0852643003 0858883002 07...   \n",
       "3  0448509014 0573085028 0751471001 0706016001 06...   \n",
       "4  0730683050 0791587015 0896152002 0818320001 09...   \n",
       "\n",
       "                                         prediction1  \\\n",
       "0  0568601043 0568601006 0656719005 0745232001 07...   \n",
       "1  0826211002 0800436010 0739590027 0723529001 08...   \n",
       "2  0794321007 0852643001 0852643003 0858883002 07...   \n",
       "3  0448509014 0573085028 0751471001 0706016001 06...   \n",
       "4  0730683050 0791587015 0896152002 0818320001 09...   \n",
       "\n",
       "                                         prediction2  \n",
       "0  0568601043 0924243001 0924243002 0918522001 07...  \n",
       "1  0924243001 0924243002 0918522001 0751471001 04...  \n",
       "2  0794321007 0924243001 0924243002 0918522001 07...  \n",
       "3  0924243001 0924243002 0918522001 0751471001 04...  \n",
       "4  0924243001 0924243002 0918522001 0751471001 04...  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub0.columns = ['customer_id', 'prediction0']\n",
    "sub0['prediction1'] = sub1['prediction']\n",
    "sub0['prediction2'] = sub2['prediction']\n",
    "del sub1, sub2\n",
    "gc.collect()\n",
    "sub0.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "81843509",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:22:26.383905Z",
     "iopub.status.busy": "2022-03-20T02:22:26.254160Z",
     "iopub.status.idle": "2022-03-20T02:26:05.565638Z",
     "shell.execute_reply": "2022-03-20T02:26:05.566210Z",
     "shell.execute_reply.started": "2022-03-19T09:06:27.705565Z"
    },
    "papermill": {
     "duration": 219.388709,
     "end_time": "2022-03-20T02:26:05.566402",
     "exception": false,
     "start_time": "2022-03-20T02:22:26.177693",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction0</th>\n",
       "      <th>prediction1</th>\n",
       "      <th>prediction2</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 07...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 07...</td>\n",
       "      <td>0568601043 0924243001 0924243002 0918522001 07...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0739590027 0723529001 08...</td>\n",
       "      <td>0826211002 0800436010 0739590027 0723529001 08...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 07...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 07...</td>\n",
       "      <td>0794321007 0924243001 0924243002 0918522001 07...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0751471001 0706016001 06...</td>\n",
       "      <td>0448509014 0573085028 0751471001 0706016001 06...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0896152002 0818320001 09...</td>\n",
       "      <td>0730683050 0791587015 0896152002 0818320001 09...</td>\n",
       "      <td>0924243001 0924243002 0918522001 0751471001 04...</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                         prediction0  \\\n",
       "0  0568601043 0568601006 0656719005 0745232001 07...   \n",
       "1  0826211002 0800436010 0739590027 0723529001 08...   \n",
       "2  0794321007 0852643001 0852643003 0858883002 07...   \n",
       "3  0448509014 0573085028 0751471001 0706016001 06...   \n",
       "4  0730683050 0791587015 0896152002 0818320001 09...   \n",
       "\n",
       "                                         prediction1  \\\n",
       "0  0568601043 0568601006 0656719005 0745232001 07...   \n",
       "1  0826211002 0800436010 0739590027 0723529001 08...   \n",
       "2  0794321007 0852643001 0852643003 0858883002 07...   \n",
       "3  0448509014 0573085028 0751471001 0706016001 06...   \n",
       "4  0730683050 0791587015 0896152002 0818320001 09...   \n",
       "\n",
       "                                         prediction2  \\\n",
       "0  0568601043 0924243001 0924243002 0918522001 07...   \n",
       "1  0924243001 0924243002 0918522001 0751471001 04...   \n",
       "2  0794321007 0924243001 0924243002 0918522001 07...   \n",
       "3  0924243001 0924243002 0918522001 0751471001 04...   \n",
       "4  0924243001 0924243002 0918522001 0751471001 04...   \n",
       "\n",
       "                                          prediction  \n",
       "0  0568601043 0568601006 0656719005 0745232001 09...  \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...  \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...  \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...  \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def cust_blend(dt, W = [1,1,1]):\n",
    "    #Global ensemble weights\n",
    "    #W = [1.15,0.95,0.85]\n",
    "    \n",
    "    #Create a list of all model predictions\n",
    "    REC = []\n",
    "    REC.append(dt['prediction0'].split())\n",
    "    REC.append(dt['prediction1'].split())\n",
    "    REC.append(dt['prediction2'].split())\n",
    "    \n",
    "    #Create a dictionary of items recommended. \n",
    "    #Assign a weight according the order of appearance and multiply by global weights\n",
    "    res = {}\n",
    "    for M in range(len(REC)):\n",
    "        for n, v in enumerate(REC[M]):\n",
    "            if v in res:\n",
    "                res[v] += (W[M]/(n+1))\n",
    "            else:\n",
    "                res[v] = (W[M]/(n+1))\n",
    "    \n",
    "    # Sort dictionary by item weights\n",
    "    res = list(dict(sorted(res.items(), key=lambda item: -item[1])).keys())\n",
    "    \n",
    "    # Return the top 12 itens only\n",
    "    return ' '.join(res[:12])\n",
    "\n",
    "sub0['prediction'] = sub0.apply(cust_blend, W = [1.05,1.00,0.95], axis=1)\n",
    "sub0.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0d39bc15",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:26:05.807778Z",
     "iopub.status.busy": "2022-03-20T02:26:05.806566Z",
     "iopub.status.idle": "2022-03-20T02:26:17.032326Z",
     "shell.execute_reply": "2022-03-20T02:26:17.031696Z",
     "shell.execute_reply.started": "2022-03-19T09:09:54.008829Z"
    },
    "papermill": {
     "duration": 11.394565,
     "end_time": "2022-03-20T02:26:17.032497",
     "exception": false,
     "start_time": "2022-03-20T02:26:05.637932",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "del sub0['prediction0']\n",
    "del sub0['prediction1']\n",
    "del sub0['prediction2']\n",
    "gc.collect()\n",
    "sub0.to_csv(f'submission.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "572a907a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:26:17.283022Z",
     "iopub.status.busy": "2022-03-20T02:26:17.281031Z",
     "iopub.status.idle": "2022-03-20T02:26:17.287735Z",
     "shell.execute_reply": "2022-03-20T02:26:17.287053Z",
     "shell.execute_reply.started": "2022-03-19T09:10:04.696284Z"
    },
    "papermill": {
     "duration": 0.183306,
     "end_time": "2022-03-20T02:26:17.287888",
     "exception": false,
     "start_time": "2022-03-20T02:26:17.104582",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del sub0\n",
    "del df\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91a7316f",
   "metadata": {
    "papermill": {
     "duration": 0.072866,
     "end_time": "2022-03-20T02:26:17.434227",
     "exception": false,
     "start_time": "2022-03-20T02:26:17.361361",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 3. Create dataset and train model with Recbole\n",
    "\n",
    "For anyone need instruction document, please check this link: https://recbole.io/docs/user_guide/usage/use_modules.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "861094fc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:26:17.582780Z",
     "iopub.status.busy": "2022-03-20T02:26:17.581666Z",
     "iopub.status.idle": "2022-03-20T02:26:20.280026Z",
     "shell.execute_reply": "2022-03-20T02:26:20.280632Z",
     "shell.execute_reply.started": "2022-03-19T09:10:04.781373Z"
    },
    "papermill": {
     "duration": 2.773509,
     "end_time": "2022-03-20T02:26:20.280830",
     "exception": false,
     "start_time": "2022-03-20T02:26:17.507321",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import logging\n",
    "from logging import getLogger\n",
    "from recbole.config import Config\n",
    "from recbole.data import create_dataset, data_preparation\n",
    "from recbole.model.sequential_recommender import GRU4Rec\n",
    "from recbole.trainer import Trainer\n",
    "from recbole.utils import init_seed, init_logger"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c211ad36",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:26:20.438539Z",
     "iopub.status.busy": "2022-03-20T02:26:20.437533Z",
     "iopub.status.idle": "2022-03-20T02:26:21.300145Z",
     "shell.execute_reply": "2022-03-20T02:26:21.007505Z",
     "shell.execute_reply.started": "2022-03-19T09:10:07.54699Z"
    },
    "papermill": {
     "duration": 0.946555,
     "end_time": "2022-03-20T02:26:21.300340",
     "exception": false,
     "start_time": "2022-03-20T02:26:20.353785",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "General Hyper Parameters:\n",
      "gpu_id = 0\n",
      "use_gpu = True\n",
      "seed = 2020\n",
      "state = INFO\n",
      "reproducibility = True\n",
      "data_path = /kaggle/working/recbox_data\n",
      "checkpoint_dir = saved\n",
      "show_progress = True\n",
      "save_dataset = False\n",
      "dataset_save_path = None\n",
      "save_dataloaders = False\n",
      "dataloaders_save_path = None\n",
      "log_wandb = False\n",
      "\n",
      "Training Hyper Parameters:\n",
      "epochs = 50\n",
      "train_batch_size = 2048\n",
      "learner = adam\n",
      "learning_rate = 0.001\n",
      "neg_sampling = None\n",
      "eval_step = 1\n",
      "stopping_step = 10\n",
      "clip_grad_norm = None\n",
      "weight_decay = 0.0\n",
      "loss_decimal_place = 4\n",
      "\n",
      "Evaluation Hyper Parameters:\n",
      "eval_args = {'split': {'RS': [10, 0, 0]}, 'group_by': 'user', 'order': 'TO', 'mode': 'full'}\n",
      "repeatable = True\n",
      "metrics = ['Recall', 'MRR', 'NDCG', 'Hit', 'Precision']\n",
      "topk = [10]\n",
      "valid_metric = MRR@10\n",
      "valid_metric_bigger = True\n",
      "eval_batch_size = 4096\n",
      "metric_decimal_place = 4\n",
      "\n",
      "Dataset Hyper Parameters:\n",
      "field_separator = \t\n",
      "seq_separator =  \n",
      "USER_ID_FIELD = user_id\n",
      "ITEM_ID_FIELD = item_id\n",
      "RATING_FIELD = rating\n",
      "TIME_FIELD = timestamp\n",
      "seq_len = None\n",
      "LABEL_FIELD = label\n",
      "threshold = None\n",
      "NEG_PREFIX = neg_\n",
      "load_col = {'inter': ['user_id', 'item_id', 'timestamp']}\n",
      "unload_col = None\n",
      "unused_col = None\n",
      "additional_feat_suffix = None\n",
      "rm_dup_inter = None\n",
      "val_interval = None\n",
      "filter_inter_by_user_or_item = True\n",
      "user_inter_num_interval = [30,inf)\n",
      "item_inter_num_interval = [40,inf)\n",
      "alias_of_user_id = None\n",
      "alias_of_item_id = None\n",
      "alias_of_entity_id = None\n",
      "alias_of_relation_id = None\n",
      "preload_weight = None\n",
      "normalize_field = None\n",
      "normalize_all = None\n",
      "ITEM_LIST_LENGTH_FIELD = item_length\n",
      "LIST_SUFFIX = _list\n",
      "MAX_ITEM_LIST_LENGTH = 50\n",
      "POSITION_FIELD = position_id\n",
      "HEAD_ENTITY_ID_FIELD = head_id\n",
      "TAIL_ENTITY_ID_FIELD = tail_id\n",
      "RELATION_ID_FIELD = relation_id\n",
      "ENTITY_ID_FIELD = entity_id\n",
      "benchmark_filename = None\n",
      "\n",
      "Other Hyper Parameters: \n",
      "wandb_project = recbole\n",
      "require_pow = False\n",
      "embedding_size = 64\n",
      "hidden_size = 128\n",
      "num_layers = 1\n",
      "dropout_prob = 0.3\n",
      "loss_type = CE\n",
      "MODEL_TYPE = ModelType.SEQUENTIAL\n",
      "MODEL_INPUT_TYPE = InputType.POINTWISE\n",
      "eval_type = EvaluatorType.RANKING\n",
      "device = cuda\n",
      "train_neg_sample_args = {'strategy': 'none'}\n",
      "eval_neg_sample_args = {'strategy': 'full', 'distribution': 'uniform'}\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "parameter_dict = {\n",
    "    'data_path': '/kaggle/working',\n",
    "    'USER_ID_FIELD': 'user_id',\n",
    "    'ITEM_ID_FIELD': 'item_id',\n",
    "    'TIME_FIELD': 'timestamp',\n",
    "    'user_inter_num_interval': \"[30,inf)\",\n",
    "    'item_inter_num_interval': \"[40,inf)\",\n",
    "    'load_col': {'inter': ['user_id', 'item_id', 'timestamp']},\n",
    "    'neg_sampling': None,\n",
    "    'epochs': 50,\n",
    "    'eval_args': {\n",
    "        'split': {'RS': [10, 0, 0]},\n",
    "        'group_by': 'user',\n",
    "        'order': 'TO',\n",
    "        'mode': 'full'}\n",
    "}\n",
    "\n",
    "config = Config(model='GRU4Rec', dataset='recbox_data', config_dict=parameter_dict)\n",
    "\n",
    "# init random seed\n",
    "init_seed(config['seed'], config['reproducibility'])\n",
    "\n",
    "# logger initialization\n",
    "init_logger(config)\n",
    "logger = getLogger()\n",
    "# Create handlers\n",
    "c_handler = logging.StreamHandler()\n",
    "c_handler.setLevel(logging.INFO)\n",
    "logger.addHandler(c_handler)\n",
    "\n",
    "# write config info into log\n",
    "logger.info(config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "548e2d03",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:26:21.722138Z",
     "iopub.status.busy": "2022-03-20T02:26:21.720998Z",
     "iopub.status.idle": "2022-03-20T02:27:55.478058Z",
     "shell.execute_reply": "2022-03-20T02:27:55.460191Z",
     "shell.execute_reply.started": "2022-03-19T09:10:08.225437Z"
    },
    "papermill": {
     "duration": 93.969404,
     "end_time": "2022-03-20T02:27:55.478219",
     "exception": false,
     "start_time": "2022-03-20T02:26:21.508815",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "recbox_data\n",
      "The number of users: 38916\n",
      "Average actions of users: 47.47241423615572\n",
      "The number of items: 10962\n",
      "Average actions of items: 168.54201259009216\n",
      "The number of inters: 1847389\n",
      "The sparsity of the dataset: 99.56694768867584%\n",
      "Remain Fields: ['user_id', 'item_id', 'timestamp']\n"
     ]
    }
   ],
   "source": [
    "dataset = create_dataset(config)\n",
    "logger.info(dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7c74775e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:27:55.906921Z",
     "iopub.status.busy": "2022-03-20T02:27:55.906288Z",
     "iopub.status.idle": "2022-03-20T02:28:37.269123Z",
     "shell.execute_reply": "2022-03-20T02:28:37.252513Z",
     "shell.execute_reply.started": "2022-03-19T09:11:36.745731Z"
    },
    "papermill": {
     "duration": 41.580573,
     "end_time": "2022-03-20T02:28:37.269274",
     "exception": false,
     "start_time": "2022-03-20T02:27:55.688701",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Training]: train_batch_size = [2048] negative sampling: [None]\n",
      "[Evaluation]: eval_batch_size = [4096] eval_args: [{'split': {'RS': [10, 0, 0]}, 'group_by': 'user', 'order': 'TO', 'mode': 'full'}]\n"
     ]
    }
   ],
   "source": [
    "# dataset splitting\n",
    "train_data, valid_data, test_data = data_preparation(config, dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9645ae09",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:28:37.715732Z",
     "iopub.status.busy": "2022-03-20T02:28:37.714892Z",
     "iopub.status.idle": "2022-03-20T02:50:21.046599Z",
     "shell.execute_reply": "2022-03-20T02:50:21.045317Z",
     "shell.execute_reply.started": "2022-03-19T09:12:13.351077Z"
    },
    "papermill": {
     "duration": 1303.559679,
     "end_time": "2022-03-20T02:50:21.046804",
     "exception": false,
     "start_time": "2022-03-20T02:28:37.487125",
     "status": "completed"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "GRU4Rec(\n",
      "  (item_embedding): Embedding(10962, 64, padding_idx=0)\n",
      "  (emb_dropout): Dropout(p=0.3, inplace=False)\n",
      "  (gru_layers): GRU(64, 128, bias=False, batch_first=True)\n",
      "  (dense): Linear(in_features=128, out_features=64, bias=True)\n",
      "  (loss_fct): CrossEntropyLoss()\n",
      ")\n",
      "Trainable parameters: 783552\n",
      "epoch 0 training [time: 29.21s, train loss: 7608.2684]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 1 training [time: 26.44s, train loss: 7102.8474]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 2 training [time: 25.82s, train loss: 6864.3110]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 3 training [time: 25.81s, train loss: 6658.3106]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 4 training [time: 25.81s, train loss: 6516.7922]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 5 training [time: 25.82s, train loss: 6418.4797]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 6 training [time: 25.55s, train loss: 6338.6159]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 7 training [time: 26.08s, train loss: 6273.0269]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 8 training [time: 25.75s, train loss: 6216.3229]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 9 training [time: 25.85s, train loss: 6168.1504]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 10 training [time: 25.45s, train loss: 6125.8122]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 11 training [time: 25.87s, train loss: 6088.1390]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 12 training [time: 25.71s, train loss: 6056.3469]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 13 training [time: 25.75s, train loss: 6028.3020]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 14 training [time: 25.52s, train loss: 6002.9929]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 15 training [time: 25.74s, train loss: 5981.4722]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 16 training [time: 25.50s, train loss: 5962.1978]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 17 training [time: 25.69s, train loss: 5946.1110]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 18 training [time: 25.66s, train loss: 5931.8931]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 19 training [time: 25.61s, train loss: 5918.5745]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 20 training [time: 25.33s, train loss: 5907.3241]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 21 training [time: 25.86s, train loss: 5897.1385]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 22 training [time: 25.55s, train loss: 5887.6680]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 23 training [time: 25.80s, train loss: 5879.6025]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 24 training [time: 25.52s, train loss: 5871.1030]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 25 training [time: 25.84s, train loss: 5864.6343]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 26 training [time: 25.54s, train loss: 5858.6181]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 27 training [time: 25.94s, train loss: 5851.7828]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 28 training [time: 25.66s, train loss: 5846.2326]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 29 training [time: 25.61s, train loss: 5840.5342]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 30 training [time: 25.72s, train loss: 5836.3762]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 31 training [time: 25.81s, train loss: 5831.4665]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 32 training [time: 25.65s, train loss: 5826.3515]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 33 training [time: 26.00s, train loss: 5822.0054]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 34 training [time: 25.27s, train loss: 5818.5471]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 35 training [time: 25.82s, train loss: 5814.4312]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 36 training [time: 25.81s, train loss: 5810.0819]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 37 training [time: 25.82s, train loss: 5807.7266]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 38 training [time: 25.45s, train loss: 5803.9869]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 39 training [time: 26.11s, train loss: 5801.2985]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 40 training [time: 25.86s, train loss: 5798.3783]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 41 training [time: 26.02s, train loss: 5795.3381]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 42 training [time: 26.13s, train loss: 5792.3586]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 43 training [time: 25.52s, train loss: 5789.8296]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 44 training [time: 25.86s, train loss: 5787.6979]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 45 training [time: 26.05s, train loss: 5785.8937]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 46 training [time: 25.78s, train loss: 5782.2815]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 47 training [time: 25.79s, train loss: 5781.2301]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 48 training [time: 25.52s, train loss: 5777.6824]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n",
      "epoch 49 training [time: 25.87s, train loss: 5776.9169]\n",
      "Saving current: saved/GRU4Rec-Mar-20-2022_02-28-47.pth\n"
     ]
    }
   ],
   "source": [
    "# model loading and initialization\n",
    "model = GRU4Rec(config, train_data.dataset).to(config['device'])\n",
    "logger.info(model)\n",
    "\n",
    "# trainer loading and initialization\n",
    "trainer = Trainer(config, model)\n",
    "\n",
    "# model training\n",
    "best_valid_score, best_valid_result = trainer.fit(train_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da91afeb",
   "metadata": {
    "papermill": {
     "duration": 0.386664,
     "end_time": "2022-03-20T02:50:21.838866",
     "exception": false,
     "start_time": "2022-03-20T02:50:21.452202",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 4. Create recommendation result from trained model\n",
    "\n",
    "I note document here for any one want to customize it: https://recbole.io/docs/user_guide/usage/case_study.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3303aa1c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:50:22.633719Z",
     "iopub.status.busy": "2022-03-20T02:50:22.632377Z",
     "iopub.status.idle": "2022-03-20T02:50:22.639114Z",
     "shell.execute_reply": "2022-03-20T02:50:22.639669Z",
     "shell.execute_reply.started": "2022-03-19T09:13:42.897843Z"
    },
    "papermill": {
     "duration": 0.407741,
     "end_time": "2022-03-20T02:50:22.639886",
     "exception": false,
     "start_time": "2022-03-20T02:50:22.232145",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "external_user_ids = dataset.id2token(\n",
    "    dataset.uid_field, list(range(dataset.user_num)))[1:]#fist element in array is 'PAD'(default of Recbole) ->remove it "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "77a87d57",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:50:23.765193Z",
     "iopub.status.busy": "2022-03-20T02:50:23.764128Z",
     "iopub.status.idle": "2022-03-20T02:50:23.775557Z",
     "shell.execute_reply": "2022-03-20T02:50:23.776880Z",
     "shell.execute_reply.started": "2022-03-19T09:17:48.660391Z"
    },
    "papermill": {
     "duration": 0.703287,
     "end_time": "2022-03-20T02:50:23.777164",
     "exception": false,
     "start_time": "2022-03-20T02:50:23.073877",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "from recbole.data.interaction import Interaction\n",
    "\n",
    "def add_last_item(old_interaction, last_item_id, max_len=50):\n",
    "    new_seq_items = old_interaction['item_id_list'][-1]\n",
    "    if old_interaction['item_length'][-1].item() < max_len:\n",
    "        new_seq_items[old_interaction['item_length'][-1].item()] = last_item_id\n",
    "    else:\n",
    "        new_seq_items = torch.roll(new_seq_items, -1)\n",
    "        new_seq_items[-1] = last_item_id\n",
    "    return new_seq_items.view(1, len(new_seq_items))\n",
    "\n",
    "def predict_for_all_item(external_user_id, dataset, model):\n",
    "    model.eval()\n",
    "    with torch.no_grad():\n",
    "        uid_series = dataset.token2id(dataset.uid_field, [external_user_id])\n",
    "        index = np.isin(dataset[dataset.uid_field].numpy(), uid_series)\n",
    "        input_interaction = dataset[index]\n",
    "        test = {\n",
    "            'item_id_list': add_last_item(input_interaction, \n",
    "                                          input_interaction['item_id'][-1].item(), model.max_seq_length),\n",
    "            'item_length': torch.tensor(\n",
    "                [input_interaction['item_length'][-1].item() + 1\n",
    "                 if input_interaction['item_length'][-1].item() < model.max_seq_length else model.max_seq_length])\n",
    "        }\n",
    "        new_inter = Interaction(test)\n",
    "        new_inter = new_inter.to(config['device'])\n",
    "        new_scores = model.full_sort_predict(new_inter)\n",
    "        new_scores = new_scores.view(-1, test_data.dataset.item_num)\n",
    "        new_scores[:, 0] = -np.inf  # set scores of [pad] to -inf\n",
    "    return torch.topk(new_scores, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "dacd5516",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:50:24.598660Z",
     "iopub.status.busy": "2022-03-20T02:50:24.597549Z",
     "iopub.status.idle": "2022-03-20T02:50:24.753648Z",
     "shell.execute_reply": "2022-03-20T02:50:24.752884Z",
     "shell.execute_reply.started": "2022-03-19T09:18:08.614523Z"
    },
    "papermill": {
     "duration": 0.545835,
     "end_time": "2022-03-20T02:50:24.753849",
     "exception": false,
     "start_time": "2022-03-20T02:50:24.208014",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.return_types.topk(\n",
       "values=tensor([[7.9712, 7.7557, 6.3152, 6.0824, 6.0296, 5.8736, 5.8550, 5.8297, 5.8106,\n",
       "         5.7406]], device='cuda:0'),\n",
       "indices=tensor([[6713, 6663, 8766,  496, 8749, 2763, 3097, 2117,  643, 2838]],\n",
       "       device='cuda:0'))"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict_for_all_item('0109ad0b5a76924a1b58be677409bb601cc8bead9a87b8ce5b08a4a1f5bc71ef', \n",
    "                     dataset, model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bb8ef264",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T02:50:25.539828Z",
     "iopub.status.busy": "2022-03-20T02:50:25.538457Z",
     "iopub.status.idle": "2022-03-20T03:16:02.324679Z",
     "shell.execute_reply": "2022-03-20T03:16:02.323774Z",
     "shell.execute_reply.started": "2022-03-19T09:18:22.091273Z"
    },
    "papermill": {
     "duration": 1537.179191,
     "end_time": "2022-03-20T03:16:02.324943",
     "exception": false,
     "start_time": "2022-03-20T02:50:25.145752",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38915\n"
     ]
    }
   ],
   "source": [
    "topk_items = []\n",
    "for external_user_id in external_user_ids:\n",
    "    _, topk_iid_list = predict_for_all_item(external_user_id, dataset, model)\n",
    "    last_topk_iid_list = topk_iid_list[-1]\n",
    "    external_item_list = dataset.id2token(dataset.iid_field, last_topk_iid_list.cpu()).tolist()\n",
    "    topk_items.append(external_item_list)\n",
    "print(len(topk_items))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "11a06a38",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:03.112776Z",
     "iopub.status.busy": "2022-03-20T03:16:03.111650Z",
     "iopub.status.idle": "2022-03-20T03:16:03.147289Z",
     "shell.execute_reply": "2022-03-20T03:16:03.147869Z",
     "shell.execute_reply.started": "2022-03-19T09:43:08.156694Z"
    },
    "papermill": {
     "duration": 0.436152,
     "end_time": "2022-03-20T03:16:03.148114",
     "exception": false,
     "start_time": "2022-03-20T03:16:02.711962",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0010e8eb18f131e724d6997909af0808adbba057529edb...</td>\n",
       "      <td>0372860001 0706016003 0706016001 0610776002 08...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0064cd1ee810d4caabd1182a8f177479b82b18961bd76b...</td>\n",
       "      <td>0894956001 0907527001 0905957001 0769748014 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>00ce4f170d9fe36d0aacca94addfc3b07f70f81dc7bde3...</td>\n",
       "      <td>0881244001 0867966009 0889652001 0750422039 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00d7ebd46f6a6d53630d41386b6ef6a505cdc4c80011ff...</td>\n",
       "      <td>0918522001 0915526001 0751592001 0924243001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00eebac2c2e37626461e74e8395711964c4e01a7afa643...</td>\n",
       "      <td>0866731001 0875350003 0915526001 0933891001 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  0010e8eb18f131e724d6997909af0808adbba057529edb...   \n",
       "1  0064cd1ee810d4caabd1182a8f177479b82b18961bd76b...   \n",
       "2  00ce4f170d9fe36d0aacca94addfc3b07f70f81dc7bde3...   \n",
       "3  00d7ebd46f6a6d53630d41386b6ef6a505cdc4c80011ff...   \n",
       "4  00eebac2c2e37626461e74e8395711964c4e01a7afa643...   \n",
       "\n",
       "                                          prediction  \n",
       "0  0372860001 0706016003 0706016001 0610776002 08...  \n",
       "1  0894956001 0907527001 0905957001 0769748014 07...  \n",
       "2  0881244001 0867966009 0889652001 0750422039 07...  \n",
       "3  0918522001 0915526001 0751592001 0924243001 09...  \n",
       "4  0866731001 0875350003 0915526001 0933891001 08...  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "external_item_str = [' '.join(x) for x in topk_items]\n",
    "result = pd.DataFrame(external_user_ids, columns=['customer_id'])\n",
    "result['prediction'] = external_item_str\n",
    "result.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "89ea3162",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:04.533514Z",
     "iopub.status.busy": "2022-03-20T03:16:04.531232Z",
     "iopub.status.idle": "2022-03-20T03:16:04.536176Z",
     "shell.execute_reply": "2022-03-20T03:16:04.535590Z",
     "shell.execute_reply.started": "2022-03-19T09:45:15.244813Z"
    },
    "papermill": {
     "duration": 0.668816,
     "end_time": "2022-03-20T03:16:04.536353",
     "exception": false,
     "start_time": "2022-03-20T03:16:03.867537",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del external_item_str\n",
    "del topk_items\n",
    "del external_user_ids\n",
    "del train_data\n",
    "del valid_data\n",
    "del test_data\n",
    "del model\n",
    "del Trainer\n",
    "del logger\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5d6fe3a8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:05.551146Z",
     "iopub.status.busy": "2022-03-20T03:16:05.370774Z",
     "iopub.status.idle": "2022-03-20T03:16:05.554678Z",
     "shell.execute_reply": "2022-03-20T03:16:05.555311Z",
     "shell.execute_reply.started": "2022-03-19T09:46:46.555935Z"
    },
    "papermill": {
     "duration": 0.635722,
     "end_time": "2022-03-20T03:16:05.555501",
     "exception": false,
     "start_time": "2022-03-20T03:16:04.919779",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del dataset\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8906703f",
   "metadata": {
    "papermill": {
     "duration": 0.392395,
     "end_time": "2022-03-20T03:16:06.331419",
     "exception": false,
     "start_time": "2022-03-20T03:16:05.939024",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# 5. Combine result from most bought items and GRU model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "27c4d836",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:07.110312Z",
     "iopub.status.busy": "2022-03-20T03:16:07.109301Z",
     "iopub.status.idle": "2022-03-20T03:16:10.656448Z",
     "shell.execute_reply": "2022-03-20T03:16:10.655419Z",
     "shell.execute_reply.started": "2022-03-19T09:46:59.90542Z"
    },
    "papermill": {
     "duration": 3.936122,
     "end_time": "2022-03-20T03:16:10.656605",
     "exception": false,
     "start_time": "2022-03-20T03:16:06.720483",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1371980, 2)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df = pd.read_csv('submission.csv')\n",
    "submit_df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d12785d1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:11.465716Z",
     "iopub.status.busy": "2022-03-20T03:16:11.464599Z",
     "iopub.status.idle": "2022-03-20T03:16:11.468743Z",
     "shell.execute_reply": "2022-03-20T03:16:11.469366Z",
     "shell.execute_reply.started": "2022-03-19T09:47:03.369678Z"
    },
    "papermill": {
     "duration": 0.422846,
     "end_time": "2022-03-20T03:16:11.469547",
     "exception": false,
     "start_time": "2022-03-20T03:16:11.046701",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                          prediction  \n",
       "0  0568601043 0568601006 0656719005 0745232001 09...  \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...  \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...  \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...  \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "102363f9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:12.249718Z",
     "iopub.status.busy": "2022-03-20T03:16:12.248055Z",
     "iopub.status.idle": "2022-03-20T03:16:13.361191Z",
     "shell.execute_reply": "2022-03-20T03:16:13.360487Z",
     "shell.execute_reply.started": "2022-03-19T09:47:03.384134Z"
    },
    "papermill": {
     "duration": 1.505033,
     "end_time": "2022-03-20T03:16:13.361342",
     "exception": false,
     "start_time": "2022-03-20T03:16:11.856309",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction_x</th>\n",
       "      <th>prediction_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                        prediction_x prediction_y  \n",
       "0  0568601043 0568601006 0656719005 0745232001 09...          NaN  \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...          NaN  \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...          NaN  \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...          NaN  \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...          NaN  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df = pd.merge(submit_df, result, on='customer_id', how='outer')\n",
    "submit_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ea585e0c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:14.288474Z",
     "iopub.status.busy": "2022-03-20T03:16:14.287176Z",
     "iopub.status.idle": "2022-03-20T03:16:44.750560Z",
     "shell.execute_reply": "2022-03-20T03:16:44.751188Z",
     "shell.execute_reply.started": "2022-03-19T09:47:04.438889Z"
    },
    "papermill": {
     "duration": 30.99182,
     "end_time": "2022-03-20T03:16:44.751372",
     "exception": false,
     "start_time": "2022-03-20T03:16:13.759552",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction_x</th>\n",
       "      <th>prediction_y</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "      <td>-1</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "      <td>-1</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "      <td>-1</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "      <td>-1</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "      <td>-1</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                        prediction_x prediction_y  \\\n",
       "0  0568601043 0568601006 0656719005 0745232001 09...           -1   \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...           -1   \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...           -1   \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...           -1   \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...           -1   \n",
       "\n",
       "                                          prediction  \n",
       "0  0568601043 0568601006 0656719005 0745232001 09...  \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...  \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...  \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...  \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df = submit_df.fillna(-1)\n",
    "submit_df['prediction'] = submit_df.apply(\n",
    "    lambda x: x['prediction_y'] if x['prediction_y'] != -1 else x['prediction_x'], axis=1)\n",
    "submit_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "754283af",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:45.707218Z",
     "iopub.status.busy": "2022-03-20T03:16:45.705648Z",
     "iopub.status.idle": "2022-03-20T03:16:45.923952Z",
     "shell.execute_reply": "2022-03-20T03:16:45.924550Z",
     "shell.execute_reply.started": "2022-03-19T09:47:34.25912Z"
    },
    "papermill": {
     "duration": 0.781266,
     "end_time": "2022-03-20T03:16:45.924737",
     "exception": false,
     "start_time": "2022-03-20T03:16:45.143471",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction_x</th>\n",
       "      <th>prediction_y</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>00009d946eec3ea54add5ba56d5210ea898def4b46c685...</td>\n",
       "      <td>0891899004 0562245099 0797892001 0516859008 07...</td>\n",
       "      <td>0568597007 0568601007 0831450002 0881244001 05...</td>\n",
       "      <td>0568597007 0568601007 0831450002 0881244001 05...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>0001d44dbe7f6c4b35200abdb052c77a87596fe1bdcc37...</td>\n",
       "      <td>0734592001 0888024005 0572998013 0909869004 08...</td>\n",
       "      <td>0891591001 0933706001 0919499007 0911214001 09...</td>\n",
       "      <td>0891591001 0933706001 0919499007 0911214001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>0006d3ff0caf0cb4d4e0615ee5cb7d268622364d483335...</td>\n",
       "      <td>0930829001 0915529001 0870525005 0751471041 05...</td>\n",
       "      <td>0884319006 0928088001 0915529001 0832307007 09...</td>\n",
       "      <td>0884319006 0928088001 0915529001 0832307007 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>00075ef36696a7b4ed8c83e22a4bf7ea7c90ee110991ec...</td>\n",
       "      <td>0860285001 0863595006 0824526004 0751471022 08...</td>\n",
       "      <td>0824526004 0874819002 0893059005 0893059004 08...</td>\n",
       "      <td>0824526004 0874819002 0893059005 0893059004 08...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>00080403a669b3b89d1bef1ec73ea466d95e39698d6dde...</td>\n",
       "      <td>0825771007 0784053005 0924243001 0914886003 08...</td>\n",
       "      <td>0914319001 0876147001 0868038003 0914319002 08...</td>\n",
       "      <td>0914319001 0876147001 0868038003 0914319002 08...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371778</th>\n",
       "      <td>fff624f63f0279200646a4f8bf27e5150096212d50fdd0...</td>\n",
       "      <td>0399256001 0873045001 0842755001 0885870002 08...</td>\n",
       "      <td>0842755001 0865917002 0869397001 0811900002 08...</td>\n",
       "      <td>0842755001 0865917002 0869397001 0811900002 08...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371787</th>\n",
       "      <td>fff673307d4cdbf688e4a0bcfe7f671036033dbe7eba01...</td>\n",
       "      <td>0865086004 0881916001 0711053003 0791587015 07...</td>\n",
       "      <td>0865086004 0754238024 0894956001 0852584001 09...</td>\n",
       "      <td>0865086004 0754238024 0894956001 0852584001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371876</th>\n",
       "      <td>fffabaebcc10efa0e613b58de37901e04fa25a2f90a0a8...</td>\n",
       "      <td>0652924004 0894400002 0924243001 0573937001 08...</td>\n",
       "      <td>0756904015 0854777001 0739533002 0844874012 05...</td>\n",
       "      <td>0756904015 0854777001 0739533002 0844874012 05...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371879</th>\n",
       "      <td>fffae8eb3a282d8c43c77dd2ca0621703b71e90904dfde...</td>\n",
       "      <td>0865624003 0396135007 0797892001 0817472007 07...</td>\n",
       "      <td>0729928025 0817472004 0729928001 0865624003 08...</td>\n",
       "      <td>0729928025 0817472004 0729928001 0865624003 08...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1371960</th>\n",
       "      <td>fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...</td>\n",
       "      <td>0898573003 0748269009 0905365002 0881919001 08...</td>\n",
       "      <td>0898573003 0762796013 0893141002 0915529005 08...</td>\n",
       "      <td>0898573003 0762796013 0893141002 0915529005 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>38915 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               customer_id  \\\n",
       "13       00009d946eec3ea54add5ba56d5210ea898def4b46c685...   \n",
       "38       0001d44dbe7f6c4b35200abdb052c77a87596fe1bdcc37...   \n",
       "169      0006d3ff0caf0cb4d4e0615ee5cb7d268622364d483335...   \n",
       "175      00075ef36696a7b4ed8c83e22a4bf7ea7c90ee110991ec...   \n",
       "195      00080403a669b3b89d1bef1ec73ea466d95e39698d6dde...   \n",
       "...                                                    ...   \n",
       "1371778  fff624f63f0279200646a4f8bf27e5150096212d50fdd0...   \n",
       "1371787  fff673307d4cdbf688e4a0bcfe7f671036033dbe7eba01...   \n",
       "1371876  fffabaebcc10efa0e613b58de37901e04fa25a2f90a0a8...   \n",
       "1371879  fffae8eb3a282d8c43c77dd2ca0621703b71e90904dfde...   \n",
       "1371960  fffef3b6b73545df065b521e19f64bf6fe93bfd450ab20...   \n",
       "\n",
       "                                              prediction_x  \\\n",
       "13       0891899004 0562245099 0797892001 0516859008 07...   \n",
       "38       0734592001 0888024005 0572998013 0909869004 08...   \n",
       "169      0930829001 0915529001 0870525005 0751471041 05...   \n",
       "175      0860285001 0863595006 0824526004 0751471022 08...   \n",
       "195      0825771007 0784053005 0924243001 0914886003 08...   \n",
       "...                                                    ...   \n",
       "1371778  0399256001 0873045001 0842755001 0885870002 08...   \n",
       "1371787  0865086004 0881916001 0711053003 0791587015 07...   \n",
       "1371876  0652924004 0894400002 0924243001 0573937001 08...   \n",
       "1371879  0865624003 0396135007 0797892001 0817472007 07...   \n",
       "1371960  0898573003 0748269009 0905365002 0881919001 08...   \n",
       "\n",
       "                                              prediction_y  \\\n",
       "13       0568597007 0568601007 0831450002 0881244001 05...   \n",
       "38       0891591001 0933706001 0919499007 0911214001 09...   \n",
       "169      0884319006 0928088001 0915529001 0832307007 09...   \n",
       "175      0824526004 0874819002 0893059005 0893059004 08...   \n",
       "195      0914319001 0876147001 0868038003 0914319002 08...   \n",
       "...                                                    ...   \n",
       "1371778  0842755001 0865917002 0869397001 0811900002 08...   \n",
       "1371787  0865086004 0754238024 0894956001 0852584001 09...   \n",
       "1371876  0756904015 0854777001 0739533002 0844874012 05...   \n",
       "1371879  0729928025 0817472004 0729928001 0865624003 08...   \n",
       "1371960  0898573003 0762796013 0893141002 0915529005 08...   \n",
       "\n",
       "                                                prediction  \n",
       "13       0568597007 0568601007 0831450002 0881244001 05...  \n",
       "38       0891591001 0933706001 0919499007 0911214001 09...  \n",
       "169      0884319006 0928088001 0915529001 0832307007 09...  \n",
       "175      0824526004 0874819002 0893059005 0893059004 08...  \n",
       "195      0914319001 0876147001 0868038003 0914319002 08...  \n",
       "...                                                    ...  \n",
       "1371778  0842755001 0865917002 0869397001 0811900002 08...  \n",
       "1371787  0865086004 0754238024 0894956001 0852584001 09...  \n",
       "1371876  0756904015 0854777001 0739533002 0844874012 05...  \n",
       "1371879  0729928025 0817472004 0729928001 0865624003 08...  \n",
       "1371960  0898573003 0762796013 0893141002 0915529005 08...  \n",
       "\n",
       "[38915 rows x 4 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df[submit_df['prediction_y'] != -1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "223a1931",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:46.723462Z",
     "iopub.status.busy": "2022-03-20T03:16:46.722014Z",
     "iopub.status.idle": "2022-03-20T03:16:46.839745Z",
     "shell.execute_reply": "2022-03-20T03:16:46.839187Z",
     "shell.execute_reply.started": "2022-03-19T09:47:34.685876Z"
    },
    "papermill": {
     "duration": 0.520431,
     "end_time": "2022-03-20T03:16:46.839926",
     "exception": false,
     "start_time": "2022-03-20T03:16:46.319495",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...</td>\n",
       "      <td>0568601043 0568601006 0656719005 0745232001 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...</td>\n",
       "      <td>0826211002 0800436010 0924243001 0739590027 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...</td>\n",
       "      <td>0794321007 0852643001 0852643003 0858883002 09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...</td>\n",
       "      <td>0448509014 0573085028 0924243001 0751471001 07...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...</td>\n",
       "      <td>0730683050 0791587015 0924243001 0896152002 08...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         customer_id  \\\n",
       "0  00000dbacae5abe5e23885899a1fa44253a17956c6d1c3...   \n",
       "1  0000423b00ade91418cceaf3b26c6af3dd342b51fd051e...   \n",
       "2  000058a12d5b43e67d225668fa1f8d618c13dc232df0ca...   \n",
       "3  00005ca1c9ed5f5146b52ac8639a40ca9d57aeff4d1bd2...   \n",
       "4  00006413d8573cd20ed7128e53b7b13819fe5cfc2d801f...   \n",
       "\n",
       "                                          prediction  \n",
       "0  0568601043 0568601006 0656719005 0745232001 09...  \n",
       "1  0826211002 0800436010 0924243001 0739590027 07...  \n",
       "2  0794321007 0852643001 0852643003 0858883002 09...  \n",
       "3  0448509014 0573085028 0924243001 0751471001 07...  \n",
       "4  0730683050 0791587015 0924243001 0896152002 08...  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df = submit_df.drop(columns=['prediction_y', 'prediction_x'])\n",
    "submit_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "7a361474",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-03-20T03:16:47.973860Z",
     "iopub.status.busy": "2022-03-20T03:16:47.972808Z",
     "iopub.status.idle": "2022-03-20T03:16:59.835508Z",
     "shell.execute_reply": "2022-03-20T03:16:59.836813Z",
     "shell.execute_reply.started": "2022-03-19T09:47:34.809425Z"
    },
    "papermill": {
     "duration": 12.508319,
     "end_time": "2022-03-20T03:16:59.837107",
     "exception": false,
     "start_time": "2022-03-20T03:16:47.328788",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "submit_df.to_csv('submission.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0fad61d",
   "metadata": {
    "papermill": {
     "duration": 0.414141,
     "end_time": "2022-03-20T03:17:00.840332",
     "exception": false,
     "start_time": "2022-03-20T03:17:00.426191",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 3480.556455,
   "end_time": "2022-03-20T03:17:04.204601",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2022-03-20T02:19:03.648146",
   "version": "2.3.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
